import React from "react";
import XtermTerminal from "../es";

const XtermLogger = () => {
  const testText = `2022-07-29 13:49:20,288 [main] ERROR - execute sql error
    org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:266)
    at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:252)
    at org.apache.hive.jdbc.HiveStatement.runAsyncOnServer(HiveStatement.java:318)
    at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:260)
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:93)
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:112)
    at com.sf.bdp.schetl.hive.driver.HiveDriver.main(HiveDriver.java:71)
    Caused by: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hive.service.cli.operation.Operation.toSQLException(Operation.java:388)
    at org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:193)
    at org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:276)
    at org.apache.hive.service.cli.operation.Operation.run(Operation.java:324)
    at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:505)
    at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:492)
    at org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:295)
    at org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:506)
    at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1437)
    at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1422)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
    at org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:286)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.RuntimeException: org.apache.hadoop.hive.ql.parse.SemanticException:org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeCreateTable(SemanticAnalyzer.java:11767)
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genResolvedParseTree(SemanticAnalyzer.java:10717)
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:10827)
    at org.apache.hadoop.hive.ql.parse.CalcitePlanner.analyzeInternal(CalcitePlanner.java:246)
    at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:251)
    at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:479)
    at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1253)
    at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1240)
    at org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:191)
    ... 15 more
    Caused by: java.lang.RuntimeException: org.apache.hadoop.hive.ql.parse.SemanticException:Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeCreateTable(SemanticAnalyzer.java:11764)
    ... 23 more
    Exception in thread "main" com.sf.bdp.schetl.common.exception.ScheduleException: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_1822022-07-29 13:49:20,290 [Thread-6] ERROR - execute sql error
    java.sql.SQLException: Method getQueryLog() failed. Because the stmtHandle in HiveStatement is null and the statement execution might fail.
    at org.apache.hive.jdbc.HiveStatement.getQueryLog(HiveStatement.java:894)
    at org.apache.hive.jdbc.HiveStatement.getQueryLog(HiveStatement.java:857)
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor$LogPrinter.run(HiveJdbcExecutor.java:141)
    
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:97)日志收集出错:Method getQueryLog() failed. Because the stmtHandle in HiveStatement is null and the statement execution might fail.
    
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:112)
    at com.sf.bdp.schetl.hive.driver.HiveDriver.main(HiveDriver.java:71)
    Caused by: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:266)
    at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:252)
    at org.apache.hive.jdbc.HiveStatement.runAsyncOnServer(HiveStatement.java:318)
    at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:260)
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:93)
    ... 2 more
    Caused by: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hive.service.cli.operation.Operation.toSQLException(Operation.java:388)
    at org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:193)
    at org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:276)
    at org.apache.hive.service.cli.operation.Operation.run(Operation.java:324)
    at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:505)
    at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:492)
    at org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:295)
    at org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:506)
    at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1437)
    at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1422)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
    at org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56)2022-07-29 13:49:20,292 [Hive-JDBC-Driver-ShutdownHook] INFO  - trigger Hive-JDBC-Driver shutdown.
    
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:286)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.RuntimeException: org.apache.hadoop.hive.ql.parse.SemanticException:org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeCreateTable(SemanticAnalyzer.java:11767)
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genResolvedParseTree(SemanticAnalyzer.java:10717)
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:10827)
    at org.apache.hadoop.hive.ql.parse.CalcitePlanner.analyzeInternal(CalcitePlanner.java:246)
    at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:251)`;
  const loaded = (e, api) => {
    // console.log(api.write);
    Promise.resolve().then(() => {
      testText.split(/\n/).forEach((text, i) => {
        if (i === 0) {
          api.writeln({ text, color: "YELLOW" });
        } else {
          api.writeln(text.trim());
        }
      });
    });
  };

  return (
    <div>
      <XtermTerminal
        colorRules={[{ pattern: /error.*$/gi, color: "RED" }]}
        lineTitle=""
        preLog=""
        disableStdin
        height={innerHeight}
        onLoad={loaded}
      />
    </div>
  );
};

export default XtermLogger;
